package com.hk.Test1;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

public class Calendar 
{
	public final int[] LEAP = {31,29,31,30,31,30,31,31,30,31,30,31};

	public final int[] PLAIN = {31,28,31,30,31,30,31,31,30,31,30,31};

	public boolean isLeapYear(int year)
	{
		boolean isC = false;
		if ((year%4==0 && year%100!=0) || year%400==0) 
		{
			isC =true;
		}
		return isC;
	}

	public int days(int year)
	{
		int totalDay = 0;

		for (int i = 1; i < year; i++) 
		{
			if (isLeapYear(i)) 
			{
				totalDay += 366;
			}
			else
			{
				totalDay += 365;
			}
		}
		return totalDay;
	}

	public int days(int year, int month)
	{
		int totalDay = days(year);
		
		for (int i = 1; i < month; i++) 
		{
			if (isLeapYear(year)) 
			{
				totalDay += LEAP[i - 1];
				
			}
			else{
				totalDay += PLAIN[i - 1];
			}
		}
		return totalDay;
	}
	
	public int days(int year, int month, int day)
	{
		return days(year,month)+day;
	}
	
	public int lastDay(int year, int month)
	{
		return isLeapYear(year)?LEAP[month-1]:PLAIN[month-1];
	}
	
	public void calForm2(int year, int month)
	{
		int dayOfWeek = 1+(days(year,month,1)%7)-1;
							System.out.println(days(year, month,1)%7);
		System.out.printf("		%d년\t%d월\n",year,month);
		System.out.println("일\t월\t화\t수\t목\t금\t토\t");
		
		for (int i = check(year, month)-dayOfWeek+1; i <= check(year, month); i++) 
		{

				System.out.print(i+"\t");
		}
		
		for (int i = 1; i <= lastDay(year, month); i++) 
		{
			System.out.print(i+"\t");
			if ((i+dayOfWeek)%7 == 0) 
			{
				System.out.println();
			}
		}
		for (int i = 1; i <= dayOfEnd(dayOfWeek,lastDay(year, month)); i++) 
		{
			System.out.print(i+"\t");
			
		}
		System.out.println();
	}
	
	public int dayOfEnd(int dayOfWeek, int lastDay)
	{
		int dayOfEnd = 7-((dayOfWeek+lastDay)%7);
		
		return dayOfEnd==7?0:dayOfEnd;
	}
	public int check(int year, int month){
		int lastmonth=0;
		if (month==1) {
			lastmonth = lastDay(year-1, month+11);
		}else{
			lastmonth = lastDay(year, month-1);
		}
		return lastmonth;
	}
	public void calPrint(int year)
	{
		for (int i = 1; i <= 12; i++) 
		{
			calForm2(year, i);
		}
	}
}
